﻿using MediatR;
using W.Warehouse.Read.Api.Application.Command.ReportlossesCommand;
using W.Warehouse.Repository.Interface;

namespace W.Product.API.Appliaction.CommandHandler.ReportlossesCommandHandler
{
    public class ReportlossesDelCommandHandler : IRequestHandler<ReportlossesDelCommand, int>
    {
        private readonly ILogger<ReportlossesCreateCommandHandler> _logger;
        private readonly IReportlossesRepository _reportlossesRepository;
        private readonly IReportProductRepository _reportProductRepository;
        public ReportlossesDelCommandHandler(IReportlossesRepository reportlossesRepository,
           IReportProductRepository reportProductRepository)
        {
            _reportlossesRepository = reportlossesRepository;
            _reportProductRepository = reportProductRepository;
        }
        /// <summary>
        /// 逻辑删除报损管理
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<int> Handle(ReportlossesDelCommand request, CancellationToken cancellationToken)
        {
            var list = await _reportlossesRepository.GetModelAsync(request.ReportlossesId);
            var lists=await _reportProductRepository.GetModelAsync(request.ReportlossesId).ConfigureAwait(false);

            list.IsDelete = true;
            list.DeleteName = "admin";
            list.DeleteTime = DateTime.Now;

            lists.IsDelete = true;
            lists.DeleteName= "admin";
            lists.DeleteTime = DateTime.Now;
             await _reportlossesRepository.UpdateAsync(list);
            await _reportProductRepository.UpdateAsync(lists);
            return 0;
        }
    }
}
